home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 30.8 KB | 1,013 lines | [TEXT/MPS ] |
- %
- % File: BitmapProcs.ps
- %
- % Contains: This file contains Procedures needed to render bitmap shapes and using colorsets
- %
- % Version: Technology: Quickdraw GX 1.1.x.
- %
- % Copyright: © 1991-7 by Apple Computer, Inc., all rights reserved.
- %
- %
-
- %
- %
- % Procedure: ReadRaster
- % procedure is passed as the proc to image. It depends on the value of RstrRead
- % which is set by the various bitmap procedures.
- %
- /ReadRaster { currentfile pixString RstrRead pop } Bdef
-
- %
- % Define some values in our dictionary that procs will use for drawing bitmaps.
- %
- /pixString null def
- /MaxSampleInt 0 def
- /OldGrayTransfer null def
- /OldBlackTransfer null def
- /OldRedTransfer null def
- /OldGreenTransfer null def
- /OldBlueTransfer null def
- /OldCyanTransfer null def
- /OldMagentaTransfer null def
- /OldYellowTransfer null def
-
-
- %<FF>
- % Procedure: DoBitmap
- % Procedure renders a bimtap shape.
- %
- % nPlanes width height bits/sample x y hex rowBytes DoBitmap -
- %
- % nPlanes: #color planes
- % width: The width in pixels of the bitmap.
- % height: The height in pixels of the bitmap.
- % bits/sample: pixelSize value.
- % x, y: Position of the bitmap in user space.
- % hex: Boolean, true if data will be hex.
- % rowBytes: #bytes required for one scanline.
- %
-
- /DoBitmap { save % Bitmaps use a lot of memory.
-
- 9 1 roll % Move the savelevel behind the parameters.
-
- /pixString exch string store % Allocate a string for the scanline.
- /RstrRead exch % Define the read operator based on hex value.
- {/readhexstring}
- {/readstring}
- ifelse
- load def
-
- 1 0 0 1 % Make mapping [1 0 0 1 -x -y]
- 6 -2 roll neg exch neg exch % for the image operator's matrix.
- ScratchMatrix astore % so bitmap positions properly.
-
-
- /ReadRaster load
- % Stack is now: nPlanes width height bits/sample matrix dataInProc
-
- 6 -1 roll dup 1 gt { % If #planes > 1 then
- false exch % multiple sources = false.
- GXColorImage % do a color image operation.
- } { % Else
- pop % Get rid of #components.
- image % do a standard image operation.
- } ifelse
-
- restore } Bdef
-
-
- %<FF>
- % Procedure DoImageMask:
- % Procedure renders a one bit bitmap using the ImageMask operator.
- %
- % width height x y hex rowBytes DoImageMask -
- %
- % width: The width in pixels of the bitmap.
- % height: The height in pixels of the bitmap.
- % x, y: Position of the bitmap in user space.
- % hex: Boolean, true if data will be hex.
- % rowBytes: #bytes required for one scanline.
- %
- /DoImageMask { save
-
- 1 index type /arraytype eq { % If the top parameter is an array, then this its additional mapping
- % from rasterizing shape, concat with CTM and set orMode to 1.
- exch concat % It will be restored by "restore" at end of this routine.
- 1 SetOrMode % So will this. Rasterized shapes are evil and only added to make Japanese work.
-
- EnsureDeviceResolution % We mean to be doing device res here, make sure we are
- % So we hit the fast blitter
- } if
-
- 7 1 roll % Move save level behind parameters.
-
- /pixString exch string store % Allocate a string for the scanline.
- /RstrRead exch % Define the read operator based on hex value.
- {/readhexstring}
- {/readstring}
- ifelse
- load def
- % Stack is: width height x y
- 1 0 0 1 % Make mapping [1 0 0 1 -x -y]
- 6 -2 roll neg exch neg exch % for the image operator's matrix.
- ScratchMatrix astore % so bitmap positions properly.
-
- ImageMaskSense exch % Put boolean for which bits to paint on stack.
- /ReadRaster load
- % Stack is now: nPlanes width height sense matrix dataInProc
-
- gsave ImageMaskColor CurrColorSet SetIndexedColor
- imagemask
- grestore
-
- restore } Bdef
-
-
- %<FF>
- %
- % Procedure: MakeBitmapStrings
- % Procedure makes an array of strings containg all of the data for a bitmap shape. Thus
- % we can have bitmap procedures. The data is in an array of strings becuase of the 64k
- % string limit in PostScript
- %
- %
- % hex dataSize MakeBitmapStrings stringArray
- %
- % hex: Boolean, true if data will be hex.
- % dataSize: the total number of bytes for all of the bitmap data.
- %
- % stringArray: Array of strings, left on stack.
- %
- /MakeBitmapStrings {
-
- % Allocate the array of strings:
-
-
- /@1 Xstore % Put the size into @1
-
- [ % start an array
-
- @1 -65535 0 { % Make strings in up to 64k chunks.
-
- dup 65535 gt { % More than 64k left?
-
- pop 65535 string % Yes, make a 64k string
-
- } { % Else
-
- string % Just make a string for the remainder which is on stack.
-
- } ifelse
-
- } for
-
- ] % Leave array on stack.
-
- %
- % Stack is: hex array
- %
-
- exch
-
- /RstrRead exch % Define the read operator based on hex value.
- {/readhexstring}
- {/readstring}
- ifelse
- load def
-
- dup % Leave a copy of the string array on the stack for the function result.
-
- %
- % Now read the data into the strings
- %
-
- { % array of strings is on the stack.
-
- currentfile exch RstrRead pop pop
-
- } forall
-
- } Bdef
-
-
- %<FF>
- %
- % StringDataIn: Procedure that can be passed to an image operator to get the data from
- % the string array. index must be started at zero.
- %
- % StringArray index StringDataIn StringArray index+1 dataString
- % Reads the string from the specified index in the string array.
- % Leaves the string on the stack and increments the index, left on stack.
- %
- /StringDataIn {
-
- 2 copy get exch 1 add exch
-
- } Bdef
-
-
- %<FF>
- % Procedure: DrawBitmapString
- %
- % Procedure is much like DoBitmap, only it draws the bitmap that is contained in the
- % Array of strings in the shape dict rather than reading the bitmap data from the current file
- % The shape dictionary with the entry "BitmapStrings" will be assumed to be on the dictionary stack.
- %
- % nPlanes width height bits/sample x y DrawBitmapString -
- %
- % nPlanes: #color planes
- % width: The width in pixels of the bitmap.
- % height: The height in pixels of the bitmap.
- % bits/sample: pixelSize value.
- % x, y: Position of the bitmap in user space.
- %
- /DrawBitmapString {
-
- 1 0 0 1 % Make mapping [1 0 0 1 -x -y]
- 6 -2 roll neg exch neg exch % for the image operator's matrix.
- ScratchMatrix astore % so bitmap positions properly.
-
- /StringDataIn load % DataIn proc.
-
- % Stack is now: nPlanes width height bits/sample matrix dataInProc
-
- BitmapStrings 0 % Put initial array index on stack.
- 8 2 roll % Put it behind everything except array o'strings.
-
- % Stack is now: bitStringArray index nPlanes width height bits/sample matrix dataInProc
-
- 6 -1 roll dup 1 gt { % If #planes > 1 then
- false exch % multiple sources = false.
- GXColorImage % do a color image operation.
- } { % Else
- pop % Get rid of #components.
- image % do a standard image operation.
- } ifelse
-
- pop pop % Get rid of last index and copy of string array.
-
- } Bdef
-
-
- %<FF>
- % Procedure: Draw1bitBitmapString
- %
- % Procedure is much like Do1bitBitmap, only it draws the bitmap that is contained in the
- % Array of strings in the shape dictionary rather than reading the bitmap data from the current file.
- % The shape dictionary with the entry "BitmapStrings", "colorSet" and "shapeType" will be assumed to be on the dictionary stack.
- % Additionally, it will be painted in or-mode, using the current color. This is used for bitmap
- % patterns and the pattern filling code handles the background color for copy-mode.
- %
- % width height x y Draw1bitmapString -
- %
- % width: The width in pixels of the bitmap.
- % height: The height in pixels of the bitmap.
- % x, y: Position of the bitmap in user space.
- %
- /Draw1bitBitmapString {
-
- %
- % if the shape type is /i "image" as opposed too "b" for 1 bit bitmap then paint in background color
- % for copymode by drawing rectangle to to simulate painting of zero-bits.
- %
- % Level-1 MakePatternDict will change shape type from /b to /i when lattice is not same size as bitmap.
- % This prevents PatternFill from doing a fill of the shape in the background color for copy mode.
- % And, unfortunately, from using the font cache for the bitmap shape.
- %
- shapeType /i eq CurrOrMode 0 eq and { % For image shape type in copy, use Indexed bitmap proc.
-
- 1 % One bit per sample
- 3 1 roll % Stack is: width height bits/sample x y
- DrawIndexedBitmapStrings % Invoke the procedure.
-
- } {
-
- 1 0 0 1 % Make mapping [1 0 0 1 -x -y]
- 6 -2 roll neg exch neg exch % for the image operator's matrix.
- ScratchMatrix astore % so bitmap positions properly.
-
- ImageMaskSense exch % Paint the one or zero bits based on orMode.
-
- /StringDataIn load % DataIn proc.
-
- % Stack is now: width height true matrix dataInProc
-
- BitmapStrings 0 % Put strings and initial array index on stack.
- 7 2 roll % Put it behind everything except array o'strings.
-
- % Stack is now: bitStringArray index width height matrix sense dataInProc
-
- imagemask % Draw the bitmap.
-
- pop pop % Get rid of last index and copy of string array.
-
- } ifelse
-
- } Bdef
-
-
-
- %<FF>
- % Determinte wheither or not to define the following procedure.
- %
- languagelevel 1 eq { % Only define for level-1
- statusdict /processcolors known { % If the processcolors entry is available
- statusdict /processcolors % execute the processcolors operator.
- get exec 4 ne % boolean left on stack for de-defining the procedure. set to true if processcolors was 4.
- } { % else
- true % processcolors wasn't defined, leave true, telling us to de-define the procedure.
- }ifelse
- } { % Else
- true % level-2, leave true, telling us to de-define the procedure
- } ifelse
-
- % Stack has boolean: whether or not to de-define the following procedure.
-
- {save true} {false} ifelse % If we are told to de-define, then put a save on the stack followed by a true, else leave false.
- % stack is either: <saveobj true>, or <false>
-
- %
- % RGBtoCMYKColorSetParams
- %
- % This routine converts an RGB color set to a CMYK colorset, if the printer
- % is a CMYK printer. This is because on a CMYK printer we are using the
- % transfer functions to simulate indexed colorsets when drawing images and
- % in the case of RGB, colroimage will muck with our image data using Undercolor removal
- % functions and black generation and this happens before our colorset transfer functions
- % or invoked.
- %
- % So, if the input colorspace is RGB then we will return a CMYK one.
- %
- % cmpArray1… cmpArrayN colorSpace NRGBtoCMYKColorSetParams cmpArray1… cmpArrayN colorSpace N
- % cmpArray1 through N: Array of component values for each component.
- % colorSpace: If applicable, a Level-2 ColorSpace, otherwise nil
- % N: Number of components, 1 implies gray, 3 implies rgb, 4 cmyk unless there is a colorspace
- % in which case it will be assumed that the number of components makes sense for setcolor
- %
-
-
- /RGBtoCMYKColorSetParams {
-
- dup 3 eq { % Only do anything if we are an RGB colorspace
-
- 5 -3 roll % Stack is: colorSpace N redArray greenArray blueArray
- dup length array % Stack is: colorSpace N redArray greenArray blueArray mewArray
-
- 0 1 2 index length 1 sub % Stack is: colorSpace N redArray greenArray blueArray mewArray 0 1 length-1
- { % Loop on all components., i is pushed
-
- % Stack is: colorSpace N redArray greenArray blueArray mewArray i
-
- dup 5 index exch get exch % Stack is: colorSpace N redArray greenArray blueArray mewArray red[i] i
- dup 5 index exch get exch % Stack is: colorSpace N redArray greenArray blueArray mewArray red[i] green[i] i
- dup 5 index exch get exch % Stack is: colorSpace N redArray greenArray blueArray mewArray red[i] green[i] blue[i] i
-
- % Now apply the black generation and undercolor removal to the RGB.
- % and stuff the values back into the component arrays.
-
- 4 1 roll % Stack is: colorSpace N redArray greenArray blueArray newArray i red[i] green[i] blue[i]
- setrgbcolor currentcmykcolor % This gets the printer to apply the UCR and BG functions to the rgb value and give us the cmyk we want.
-
- % Now stuff the cmyk into the 4 arrays.
-
- % Stack is: colorSpace N redArray greenArray blueArray newArray i cyan[i] magenta[i] yellow[i] black[i]
- 5 index 5 index 3 -1 roll % Stack is: colorSpace N redArray greenArray blueArray newArray i cyan[i] magenta[i] yellow[i] newArray i black[i]
- put % Stack is: colorSpace N redArray greenArray blueArray newArray i cyan[i] magenta[i] yellow[i], and we stuffed black in newArray
- 5 index 4 index 3 -1 roll % Stack is: colorSpace N redArray greenArray blueArray newArray i cyan[i] magenta[i] blueArray i yellow[i]
- put % Stack is: colorSpace N redArray greenArray blueArray newArray i cyan[i] magenta[i], and we stuffed yellow in blueArray
- 5 index 3 index 3 -1 roll % Stack is: colorSpace N redArray greenArray blueArray newArray i cyan[i] magenta[i] greenArray i magenta[i]
- put % Stack is: colorSpace N redArray greenArray blueArray newArray i cyan[i], and we stuffed magenta in greenArray
- 5 index 2 index 3 -1 roll % Stack is: colorSpace N redArray greenArray blueArray newArray i cyan[i] redArray i cyan[i]
- put % Stack is: colorSpace N redArray greenArray blueArray newArray i, and we stuffed cyan in redArray
- pop % Stack is: colorSpace N redArray greenArray blueArray mewArray
-
- } for
-
- % redArray greenArray blueArray mewArray has been transformed into cyanArray magentaArray yellowArray blackArray
-
- % stack is: colorSpace N cyanArray magentaArray yellowArray blackArray
- 6 -2 roll % stack is: cyanArray magentaArray yellowArray blackArray colorSpace N
- pop 4 % stack is: cyanArray magentaArray yellowArray blackArray colorSpace 4, ready for CreateColorSpace
-
- } if
-
- } Bdef
-
- {restore} if % De-define the procedure if we are instructed to do wo.
-
-
-
- %<FF>
- %
- % Procedure: CreateColorSet
- %
- % Procedure creates an colorSet dictionary.
- %
- % cmpArray1… cmpArrayN colorSpace N CreateColorSet dict
- %
- % cmpArray1 through N: Array of component values for each component.
- % colorSpace: If applicable, a Level-2 ColorSpace, otherwise nil
- % N: Number of components, 1 implies gray, 3 implies rgb, 4 cmyk unless there is a colorspace
- % in which case it will be assumed that the number of components makes sense for setcolor
- %
- % dict: a colorSet dictionary.
- %
- /CreateColorSet {
-
- currentdict /PortablizeColorSetParams known {PortablizeColorSetParams} if % If we are portable, make sure colorSet is.
- currentdict /RGBtoCMYKColorSetParams known {RGBtoCMYKColorSetParams} if % If we are on a CMYK level-1 device, then convert the RGB set to CMYK
-
- 5 dict begin % Create a dictionary for the colorset.
-
- exch % Swap the space and N on the stack.
- /ColorSpace Xdef % Save the color space in the dictionary.
- 1 index length /Size Xdef % Get the size of the 1st array, it should be the same for all.
- dup /Num Xdef % Save number of components in the dictionary
- array % Create an array with one element per component
- astore % Put the arrays of components into the array.
- /Components Xdef % Save this array in the components field of the dictionary.
-
- %
- % Figure out which color operator to use
- %
- ColorSpace null eq { % If there is no colorspace
- % use one of the device dependant operators.
- /SetColorOp
-
- Num 1 eq { % If it is one component
-
- /setgray load def % use setgray
-
- } { % else
-
- Num 3 eq { % If it is 3 components
- /GXSetRGBColor load def % Use setrgbcolor
- } { % else
- /setcmykcolor load def % Use setcmykcolor
- } ifelse
-
- } ifelse
-
- } { % else Use the level-2 coloer operator.
-
- /SetColorOp /setcolor load def
-
- } ifelse
-
- currentdict end
-
- } Bdef
-
- %<FF>
- %
- % Procedure: SetIndexedColor
- %
- % Procedure sets the current color to be the color in the indexed color space.
- % Warning: In level-2, this procedure also sets the current color space to be that of the ColorSet dictionary
- % and it is left that way.
- %
- % index setDict SetIndexedColor -
- %
- % index: The index of the color. (zero based)
- % setDict: A valid colorSet dictionary.
- %
- /SetIndexedColor {
-
- begin
-
- ColorSpace null ne {ColorSpace GXSetCSpace} if % Set the color space if necessary.
- Components {1 index get exch} forall pop % Get the components from the arrays.
- SetColorOp
-
- end
-
- } Bdef
-
-
-
- %<FF>
- %
- %
- % Stuff for level-2 indexed colorspace bitmaps:
- %
- languagelevel 2 ge {
-
- %
- % Lookup procedure for a level-2 indexed color space. This is passed in the array to
- % setcolorspace:
- % It expects the index of the color on the stack.
- %
- /LookupProc {
-
- CurrColorSet /Components get { % For each component:
-
- 1 index dup % Get the color index from the stack.
- CurrColorSet /Size get ge { % If the passed index is too big:
- pop pop 0 % pop off the parameters and put 0 for the component.
- } { % Else
- get % Get the component value from the array.
- } ifelse
- exch % Get component array back on top of stack.
-
- } forall
-
- pop % Get rid of duplicate component array
-
- } Bdef
-
- } if
-
-
- %<FF>
- %
- % Procedure to draw level-2 indexed color space bitmap.
- %
- languagelevel 2 ge {
-
- %
- % Procedure DoIndexedBitmap:
- % Procedure renders a bitmap shape using the current colorset. Level-2 only.
- %
- % width height bits/sample x y hex rowBytes DoIndexedBitmap -
- % width: The width in pixels of the bitmap.
- % height: The height in pixels of the bitmap.
- % bits/sample: pixelSize value.
- % x, y: Position of the bitmap in user space.
- % hex: Boolean, true if data will be hex. (ignored when data is in string array)
- % rowBytes: #bytes required for one scanline. (If 0, data is assumed to be in string array)
- %
- /DoIndexedBitmap { save
-
- 8 1 roll % Move save-level behind parameters on stack.
-
- dup 0 gt {
-
- /pixString exch string store % allocate a string for the scanline.
-
- /RstrRead exch % Define read operation based on hex value.
- {/readhexstring}
- {/readstring}
- ifelse
- load def
-
- } {
-
- pop pop % Get rid of duplicate rowBytes and hex string.
- /pixString null store % null pixString is flag for get data out of string array.
-
- } ifelse
-
- 1 0 0 1
- 6 -2 roll neg exch neg exch % Make mapping [1 0 0 1 -x -y]
- ScratchMatrix astore % for image dictionary to position bitmap correctly.
-
- % stack is now width height bits/sample matrix
-
- %
- % Define the indexed color space, old one will be restored by restore at end of this execution.
- %
- % Creating the array [ /Indexed base hival lookup ]
- [
- /Indexed
-
- CurrColorSet begin % Put the color set dictionary on the stack.
-
- ColorSpace null eq { % If the color space is null, use a device space based on Num
-
- Num 1 eq % 1 is DeviceGray
- {/DeviceGray}
- { Num 3 eq
- {/DeviceRGB} % 3 is DeviceRGB
- {/DeviceCMYK} % 4 is DeviceCMYK
- ifelse
- } ifelse
-
- } { % Else put the color space array on the stack.
- ColorSpace /CSA get
- } ifelse
- % Stack now has base color space (base)
-
- Size % Put the number of entries on the stack. (hival)
-
- end
-
- /LookupProc load % Put the lookup procedure on the stack. (lookup)
-
- ] setcolorspace
-
- % Set the color rendering dictionary, if the color space isn't null.
-
- CurrColorSet /ColorSpace get dup null ne {GXSetCRD} {pop} ifelse
-
- %
- % Create a dictionary for the image operator.
- %
- 7 dict dup begin
-
- % stack is now: width height bits/sample matrix dict
-
- 5 1 roll
- /ImageMatrix Xdef
- /BitsPerComponent Xdef
- /Height Xdef
- /Width Xdef
-
- /ImageType 1 def
- /Decode [0 2 BitsPerComponent exp 1 sub] def
-
- pixString null ne {
-
- /DataSource /ReadRaster load def
-
- } {
-
- /DataSource /StringDataIn load def
- BitmapStrings 0 % Put string array on stack and first index
- 3 2 roll % Move them behind image dictionary.
-
- } ifelse
-
- end
-
- image % Execute the image operator.
-
- % pop off array and last array index if we were reading from string.
- pixString null eq {pop pop} if
-
- restore } Bdef
-
-
- } if
-
-
- %<FF>
- %
- % Indexed color set bitmap stuff for level-1. Uses transfer functions to simulate effect.
- %
- languagelevel 1 eq {
-
- /MaxSampleInt 0 store % 2^pixelsize - 1 for current image operation.
-
- %
- % LookupComponent: For a given input value, looks up the component value in the colorset.
- %
- % input component-index LookupComponent output
- %
- % input: Input component value from 0-1.
- % comp-index: Index of color component to get.
- %
- % output: Output value for component from 0-1.
- %
- /LookupComponent {
-
- CurrColorSet /Components get % Get array of components
- exch get % Get the correct component array
- exch MaxSampleInt mul round cvi % Get index into the array.
- dup
- CurrColorSet /Size get ge { % Get it if it is in the array, else return zero.
- pop pop 0
- } {
- get
- } ifelse
-
- } Bdef
-
-
- %
- % Procedure DoIndexedBitmap:
- % Procedure renders a bitmap shape using the colorset. Level-1 version.
- % This is done by installing transfer functions which use the input value
- % to index the color set arrays.
- %
- % width height bits/sample x y hex rowBytes DoIndexedBitmap -
- % width: The width in pixels of the bitmap.
- % ` height: The height in pixels of the bitmap.
- % bits/sample: pixelSize value.
- % x, y: Position of the bitmap in user space.
- % hex: Boolean, true if data will be hex. (Ignored when data is in string array)
- % rowBytes: #bytes required for one scanline. (If 0, data is assumed to be in string array)
- %
- /DoIndexedBitmap { save
-
- 8 1 roll % Move save-level behind parameters on stack.
-
- dup 0 gt { % If data is not in string array:
-
- /pixString exch string store % allocate a string for the scanline.
-
- /RstrRead exch % Define read operation based on hex value.
- {/readhexstring}
- {/readstring}
- ifelse
- load def
-
- 2 index 2 exch exp 1 sub /MaxSampleInt exch store % Save the maximum sample integer value.
-
- InstallColorSetTransfers % Do this here, handled by PatternFill and DashStroke for string case.
-
- } { % Else data is in string array.
-
- pop pop % get rid of duplicate rowbytes and hex string.
- /pixString null store % null pixString is flag for get data out of string array.
-
- } ifelse
-
- 1 0 0 1
- 6 -2 roll neg exch neg exch % Make mapping [1 0 0 1 -x -y]
- ScratchMatrix astore % for image dictionary to position bitmap correctly.
-
- % stack is now width height bits/sample matrix
-
- CurrColorSet /Num get dup 1 eq { % 1 component is gray-scale printer.
-
- pop % Get rid of duplicate of Num
-
- pixString null ne {
-
- /ReadRaster load
-
- } {
-
- /StringDataIn load
- BitmapStrings 0 7 2 roll
-
- } ifelse
-
- image
-
- } { % Else is color device, determine rgb or cmyk
-
- 3 eq { % RGB
-
- %
- % data-source procedures. First one reads data and duplicates it twice to get other two components
- % Other two data sources do nothing. This makes it so each transfer function gets
- % the same index.
- %
- pixString null ne {
-
- {ReadRaster dup dup} {} {}
-
- } {
-
- {StringDataIn dup dup} {} {} BitmapStrings 0 9 2 roll
-
- } ifelse
-
- true 3 GXColorImage
-
- } { % CMYK
-
- % First data source procedure reads the data and duplicates it 3 times. See above comment.
- % for rgb case.
- pixString null ne {
-
- {ReadRaster dup dup dup } {} {} {}
-
- } {
-
- {StringDataIn dup dup dup} {} {} {} BitmapStrings 0 10 2 roll
-
- } ifelse
-
- true 4 GXColorImage
-
- } ifelse
-
- } ifelse
-
- pixString null eq {pop pop} if % if data was in array, pop off array and index.
-
- restore } Bdef
-
- } if
-
- %<FF>
- %
- % Procedure to install transfer functions using that map into the current color set.
- %
- languagelevel 1 eq {
-
- /InstallColorSetTransfers {
-
- CurrColorSet /Num get dup 1 eq { % 1 component is gray-scale printer.
-
- /OldGrayTransfer currenttransfer store
-
- {0 LookupComponent OldGrayTransfer} settransfer
-
- pop % Get rid of duplicate of Num
-
- } { % Else is color device, determine rgb or cmyk
-
- 3 eq { % RGB
-
- currentcolortransfer
-
- /OldGrayTransfer exch store
- /OldBlueTransfer exch store
- /OldGreenTransfer exch store
- /OldRedTransfer exch store
-
- {0 LookupComponent OldRedTransfer}
- {1 LookupComponent OldGreenTransfer}
- {2 LookupComponent OldBlueTransfer}
- {OldGrayTransfer}
- setcolortransfer
-
- } { % CMYK
-
- currentcolortransfer
-
- /OldBlackTransfer exch store
- /OldYellowTransfer exch store
- /OldMagentaTransfer exch store
- /OldCyanTransfer exch store
-
- %
- % The values must first be inverted becuase PostScript always treats transfer functions
- % in additive space. So, invert values before lookup, then invert result.
- %
- {1 exch sub 0 LookupComponent 1 exch sub OldCyanTransfer}
- {1 exch sub 1 LookupComponent 1 exch sub OldMagentaTransfer}
- {1 exch sub 2 LookupComponent 1 exch sub OldYellowTransfer}
- {1 exch sub 3 LookupComponent 1 exch sub OldBlackTransfer}
- setcolortransfer
-
- } ifelse
-
- } ifelse
-
- } Bdef
-
- } if
-
-
- %<FF>
- % Procedure calls DrawIndexedBitmap to use string array rather than current file.
- %
- % width height bits/sample x y DrawIndexedBitmapStrings -
- %
- /DrawIndexedBitmapStrings {
-
- F 0 DoIndexedBitmap % Pass 0 for rowbytes, flags DoIndexedBitmap to use strings.
-
- } Bdef
-
-
-
-
-
- %<FF>
- % Procedure Do1bitBitmap
- %
- % width height x y hex rowBytes Do1bitBitmap -
- %
- % width: The width in pixels of the bitmap.
- % ` height: The height in pixels of the bitmap.
- % x, y: Position of the bitmap in user space.
- % hex: Boolean, true if data will be hex.
- % rowBytes: #bytes required for one scanline.
- %
- %
- %
- /Do1bitBitmap {
-
- dup type /arraytype eq % If there is a matrix on top, that means bitmap is really rasterized shape, use imagemask.
- CurrOrMode 0 ne or { % or For or-mode, we can use the image mask.
-
- DoImageMask
-
- } { % Invoke the indexed bitmap procedure
-
- 1 % Put a 1 on the stack for bits/sample
- % stack is now: width height x y hex rowBytes bits/sample
- 5 1 roll % Stack is now: width height bits/sample x y hex rowBytes
-
- DoIndexedBitmap
-
- } ifelse
-
- } Bdef
-
-
-
-
- %<FF>
- % This function is called from within the definition of an image dictionary. (image dictionary must be on top of dict stack)
- % This function sets up the decode entry in the image dictionary based upon the range in the current color space array.
- %
- /SetImageDecodeEntry {
- %
- % cause pixel values to expand to color space range.
- %
- /Decode [0 1.0 0 1.0 0 1.0] def % Initialize it to be 0-1 for all components.
- currentcolorspace 0 get /CIEBasedABC eq { % But, if the current color space is a CIEBasedABC.
- currentcolorspace 1 get dup /RangeABC known { % And it has a RangeABC entry
- /RangeABC get /Decode exch def % use that as the decoding for the bitmap data.
- } { % else
- pop % Get rid of extra copy of color space dictionary.
- } ifelse % endif
- } if
-
- } bind def
-
-
- %
- %
- % Level 2 device independant color space bitmap procedures. (One for strings, one for for file input)
- % Routines set up a dictionary for the Image Operator to use the current color space
- %
- languagelevel 2 ge {
-
- %
- % Procedure: DoLevel2ColorImage
- % Procedure draws a color image in the current level-2 color space for device independent colors
- %
- % width height bits/sample x y hex DoLevel2ColorImage -
- % width: The width in pixels of the bitmap.
- % height: The height in pixels of the bitmap.
- % bits/sample: pixelSize value.
- % x, y: Position of the bitmap in user space.
- % hex: Boolean, true if data will be hex.
- %
- /DoLevel2ColorImage {
-
- 9 dict begin
-
- /ImageType 1 def
-
- % hex flag is on top of stack, define DataSource based upon value.
- {
- /DataSource currentfile /ASCIIHexDecode filter def
- } {
- /DataSource currentfile def
- } ifelse
-
- % Stack has x,y on top:, make matrix [1 0 0 1 -x -y] for ImageMatrix
-
- neg exch neg exch matrix translate /ImageMatrix Xdef
-
- /BitsPerComponent Xdef
-
- /Height Xdef
- /Width Xdef
-
- SetImageDecodeEntry % Setup the /Decode entry in the image dictionary.
-
- currentdict % Leave the image dictionary on the stack.
-
- end
-
- image % Execute the image operator on the dictionary.
-
- } Bdef
-
-
- %<FF>
- %
- % Procedure: DoLevel2ColorImageString
- % Procedure draws a color image in the current level-2 color space for device independent colors
- % Using the strings as input rather than the current file.
- % The shape dictionary with the entry "BitmapStrings" will be assumed to be on the dictionary stack.
- %
- % width height bits/sample x y DoLevel2ColorImageString -
- % width: The width in pixels of the bitmap.
- % height: The height in pixels of the bitmap.
- % bits/sample: pixelSize value.
- % x, y: Position of the bitmap in user space.
- %
- /DoLevel2ColorImageString {
-
- 9 dict begin
-
- /ImageType 1 def
-
- /DataSource /StringDataIn load def
-
- % Stack has x,y on top:, make matrix [1 0 0 1 -x -y] for ImageMatrix
-
- neg exch neg exch matrix translate /ImageMatrix Xdef
-
- /BitsPerComponent Xdef
-
- /Height Xdef
- /Width Xdef
-
- SetImageDecodeEntry % Setup the /Decode entry in the image dictionary.
-
- BitmapStrings 0 % Put the string array and the initial index on the stack.
-
- currentdict % Leave the image dictionary on the stack.
-
- end
-
- image % Execute the image operator on the dictionary.
-
- pop pop % Get rid of last index and copy of string array.
-
- } Bdef
-
- } if % language level >= 2
-